package com.ibeeking.found.msg.rest.controller.v1;

import com.ibeeking.found.common.utils.UserUtils;
import com.ibeeking.found.msg.rest.service.ISysMsgRecordReceiverService;
import com.ibeeking.found.msg.service.common.vo.SysMsgRecordVO;
import com.ibeeking.nematos.constants.enums.LogClassifyEnum;
import com.ibeeking.nematos.constants.enums.LogSourceEnum;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName SysMsgRecordController
 * @Description
 * @Author ibeeking
 * @Date 2020-12-09 10:54
 **/
@RestController
@RequestMapping("/msg/sysMsgRecord/v1")
public class SysMsgRecordController {

    @Resource
    private ISysMsgRecordReceiverService sysMsgRecordReceiverServiceImpl;

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.QUERY, describe = "系统消息查询")
    @PostMapping(value = "/listAllRecords")
    public List<SysMsgRecordVO> listAllSysMsgRecords() {
        Long tenantID = UserUtils.getTenantID();
        return sysMsgRecordReceiverServiceImpl.listByTenantAndReceiverId(tenantID, tenantID);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.QUERY, describe = "未读系统消息查询")
    @PostMapping(value = "/listAllUnReadRecords")
    public List<SysMsgRecordVO> listAllUnReadRecords() {
        Long tenantID = UserUtils.getTenantID();
        return sysMsgRecordReceiverServiceImpl.listUnReadByTenantAndReceiverId(tenantID, tenantID);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.QUERY, describe = "统计未读消息数量")
    @PostMapping(value = "/countUnReadRecords")
    public Integer countUnReadRecords() {
        Long tenantID = UserUtils.getTenantID();
        return sysMsgRecordReceiverServiceImpl.unReadCount(tenantID, tenantID);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.QUERY, describe = "消息详情")
    @PostMapping(value = "/view/{id}")
    public SysMsgRecordVO viewSysMsgRecord(@PathVariable("id") Long id) {
        return sysMsgRecordReceiverServiceImpl.viewSysMsgRecord(id);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logClassify = LogClassifyEnum.OPERATION_LOG,logType = OperateLogTypeEnum.MODIFY, describe = "邮件模板启用/禁用")
    @PostMapping(value = "/changeReadStatus/{id}/{status}")
    public Boolean changeReadStatus( @PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return sysMsgRecordReceiverServiceImpl.changeReadStatus(id, status);
    }

}
